<template>
  <div class="list">
    <div>
      <el-form size="small" :inline="true" :model="whereData" class="search-from">
        <el-form-item>
          <el-input @keyup.enter.native="init()" clearable v-model="whereData.pay_name" placeholder="收款姓名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input @keyup.enter.native="init()" clearable v-model="whereData.pay_amount" placeholder="收款账号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            style="width: 280px"
            v-model="whereData.created_at"
            type="daterange"
            range-separator="-"
            value-format="yyyy-MM-dd"
            start-placeholder="注册日期(开始)"
            end-placeholder="注册日期(结束)"
            :picker-options="pickerOptions"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="init()">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="section">
      <div class="table-title" v-if="totalInfo">
        <span>支付总额：{{(totalInfo.total_pay_money).toFixed(2)}} 元</span>
        <span>实付总额：{{(totalInfo.total_settle_money).toFixed(2)}} 元</span>
        <span>服务费：{{(totalInfo.total_pay_money - totalInfo.total_settle_money).toFixed(2)}} 元</span>
      </div>
      <el-table
        :data="tableData"
        v-loading="isLoading"
        style="width: 100%">
        <el-table-column
          align="center"
          prop="id"
          width="80px"
          sortable="custom"
          label="ID">
        </el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="pay_name"
          label="收款姓名">
        </el-table-column>
        <el-table-column align="center" prop="pay_amount" label="收款账号"></el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="pay_type"
          label="支付类型">
        </el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="created_at"
          label="导入时间">
        </el-table-column>
        <el-table-column
          align="center"
          sortable="custom"
          show-overflow-tooltip
          prop="pay_time"
          label="支付时间">
        </el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="pay_money"
          label="支付总额">
          <template slot-scope="scope">
            <span>{{scope.row.pay_money | numFilter}}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="settle_money"
          label="实付总额">
          <template slot-scope="scope">
            <span>{{scope.row.settle_money | numFilter}}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          sortable="custom"
          show-overflow-tooltip
          prop="pay_status"
          label="支付状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status === -1" size="small" type="warning">打款失败</el-tag>
            <el-tag v-else-if="scope.row.pay_status === 1" size="small" type="">等待打款</el-tag>
            <el-tag v-else-if="scope.row.pay_status === 2"  size="small" type="info">打款中</el-tag>
            <el-tag v-else-if="scope.row.pay_status === 3" size="small" type="warning">部分打款</el-tag>
            <el-tag v-else-if="scope.row.pay_status === 9" type="success">打款成功</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          sortable="custom"
          show-overflow-tooltip
          prop="pay_message"
          label="支付结果">
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  name: 'list',
  data() {
    return {
      whereData: {
        pay_amount: '',
        pay_name: ''
      },
      isLoading: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      tableData: [],
      totalInfo: [],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
    }
  },
  mounted() {
    this.init()
  },
  filters: {
    // 截取当前数据到小数点后两位
    numFilter(value) {
      const realVal = parseFloat(value).toFixed(2);
      return realVal;
    }
  },
  methods: {
    init() {
      this.$http.get(`/company/payment/records`, {
        'pay_name': this.whereData.pay_name,
        'pay_amount': this.whereData.pay_amount,
        'created_at': this.whereData.created_at,
        'page': this.pageIndex,
        'limit': this.pageSize
      }).then(res => {
        if (res.code === 0) {
          this.tableData = res.page.list
          this.totalPage = res.page.totalCount
          this.totalInfo = res.page.totalInfo
        }
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.init()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.init()
    },
    goDetail(row) {
      this.$router.push('/company/deal/settlement/detail?id=' + row.id)
    }
  }
}
</script>
<style lang="less" scoped>
.table-title {
  margin-bottom: 20px;
  font-size: 14px;
  span {
    margin-right: 20px;
  }
}
</style>
